class LabelsController < ApplicationController
  filter_access_to :all

  # GET /labels/id
  # GET /labels/id.xml
  def show
    @label = Label.find(params[:id])
    store_location
    session[:edit_mode] = false

    respond_to do |format|
      format.html
      format.xml { render :xml => @label }
    end

  end

  # GET /labels/new
  # GET /labels/new.xml
  def new
    @label = Label.new

    if params[:name]
      @label.name = params[:name]
    end

    respond_to do |format|
      format.html
      format.xml { render :xml => @label }
    end

  end

  # GET /labels/edit/it
  def edit
    @label = Label.find(params[:id])
    store_location
    session[:edit_mode] = true

    respond_to do |format|
      format.html
    end
  end

  # PUT /labels/id
  def update
    @label = Label.find(params[:id])

    respond_to do |format|
      if @label.update_attributes(params[:label])
        flash[:notice] = 'Information Updated.'
        format.html {redirect_to(@label)}
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.html { render :xml => @label.errors, :status => :unprocessable_entity }
      end
    end
  end

  # POST /labels/id
  #
  def create
    @label = Label.new(params[:label])

    respond_to do |format|
      if @label.save
        format.html {redirect_to(@label) }
        format.xml  { render :xml => @label, :status => :created, :location => @label }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @label.errors, :status => :unprocessable_entity }
      end
    end
  end

end
